Function.prototype.myCall = function(context) {
    if (typeof this !== 'function') {
        throw new Error('not a function err ！')
    }
    const args = [...arguments].slice(1)
    let result = null
    context = context || window
    context.fn = this
    result = context.fn(...args)
    delete context.fn
    return result
}

Function.prototype.myApply = function(context) {
    if (typeof this !== 'function') return new Error(`err: not a function`)
    let res = null
    context = context || window
    const fn = Symbol()
    context[fn] = this
    // 判断是否有第二个参数（数组参数）
    if (arguments[1]) {
        res = context[fn](...arguments[1])
    } else {
        res = context[fn]()
    }
    delete context[fn]
    return res
}

Function.prototype.myBind = function(context) {
    if (typeof this!== 'function') return new Error(`err: not a function`)
    const args = [...arguments].slice(1)
    const fn = this
    return function Fn() {
        const aaa = this instanceof Fn ? Fn : context
        return fn.apply(
            aaa,
            args.concat(...arguments)
        )
    }
}